﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;
using DataModels;

namespace DataAccess
{
    public class SecurityDataAccess : DataAccessBase, ISecurityDataAccess
    {
        public bool Register(Security security)
        {
            Context.AddToSecurity(security);
            int count = Context.SaveChanges();
            Context.AcceptAllChanges();

            return count > 0;
        }

        public Person Login(string username, string password)
        {
            var security = SecuritySet.Where(s => s.Username == username && s.Password == password).FirstOrDefault();

            if (security == null) return null;

            return security.Person;
        }
    }
}
